<%@ page import="cn.ecut.javabean.User" %>
<%@ page import="java.util.*" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>foreach</title>
    <style type="text/css">
        .even { background : greenyellow;}
        .odd { background : blueviolet;}
    </style>
</head>

<body>
    <%
        User user = new User() ;
        user.setPassword("123123");
        user.setName("张三");

        User user2 = new User() ;
        user2.setName("lisi");
        user2.setPassword("456789");

        User user3 = new User() ;
        user3.setName("王五");
        user3.setPassword("456789");

        User user4 = new User() ;
        user4.setName("赵六");
        user4.setPassword("456789");

        List<User> list = new ArrayList<User>() ;
        list.add( user ) ;
        list.add( user2 ) ;
        list.add( user3 ) ;
        list.add( user4 ) ;

        // 将 集合存放在 一个区域中
        request.setAttribute("userList" , list );
    %>

    <div>
        <c:forEach var="i" items="${userList}" varStatus="status">
        <c:if test="${status.index % 2 == 0}">
            <table>
            <tr class = "even">
                <td>${ status.index}</td>
                <td>${ i.name}</td>
            </tr>
        </c:if>
        <c:if test="${status.index % 2 == 1}">
            <tr  class = "odd">
                <td>${ status.index}</td>
                <td>${ i.name}</td>
            </tr>
            </table>
        </c:if>
        </c:forEach>
    </div>
    <c:forEach var="li" items="${userList }"  varStatus="status">
        <c:if test="${status.index mod 2 eq 0 }">
            <ul style="background-color:yellow;">
                <li>${status.index }</li>
                <li>${li.name }</li>
            </ul>
        </c:if>
        <c:if test="${status.index mod 2 ne 0 }">
            <ul style="background-color:lightgreen;">
                <li>${status.index }</li>
                <li>${li.name }</li>
            </ul>
        </c:if>
    </c:forEach>
</body>
</html>
